'\" t
.TH "SD_EVENT_SET_SIGNAL_EXIT" "3" "" "systemd 256.7" "sd_event_set_signal_exit"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_event_set_signal_exit \- Automatically leave event loop on \fBSIGINT\fR and \fBSIGTERM\fR
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-event\&.h>
.fi
.ft
.HP \w'int\ sd_event_set_signal_exit('u
.BI "int sd_event_set_signal_exit(sd_event\ *" "event" ", int\ b);"
.SH "DESCRIPTION"
.PP
\fBsd_event_set_signal_exit()\fR
may be used to ensure the event loop terminates once a
\fBSIGINT\fR
or
\fBSIGTERM\fR
signal is received\&. It is a convenience wrapper around invocations of
\fBsd_event_add_signal\fR(3)
for both signals\&. The two signals are automatically added to the calling thread\*(Aqs signal mask (if a program is multi\-threaded care should be taken to either invoke this function before the first thread is started or to manually block the two signals process\-wide first)\&.
.PP
If the parameter
\fIb\fR
is specified as true, the event loop will terminate on
\fBSIGINT\fR
and
\fBSIGTERM\fR\&. If specified as false, it will no longer\&. When this functionality is turned off the calling thread\*(Aqs signal mask is restored to match the state before it was turned on, for the two signals\&. By default the two signals are not handled by the event loop, and Linux\*(Aq default signal handling for them is in effect\&.
.PP
It\*(Aqs customary for UNIX programs to exit on either of these two signals, hence it\*(Aqs typically a good idea to enable this functionality for the main event loop of a program\&.
.SH "RETURN VALUE"
.PP
\fBsd_event_set_signal_exit()\fR
returns a positive non\-zero value when the setting was successfully changed\&. It returns a zero when the specified setting was already in effect\&. On failure, it returns a negative errno\-style error code\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-ECHILD\fR
.RS 4
The event loop has been created in a different process, library or module instance\&.
.sp
Added in version 252\&.
.RE
.PP
\fB\-EINVAL\fR
.RS 4
The passed event loop object was invalid\&.
.sp
Added in version 252\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_event_set_signal_exit()\fR
was added in version 252\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_add_signal\fR(3)
